package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author zr
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/edu/service/video")
//@CrossOrigin
@Api(tags = "课时管理")
public class EduVideoController {
    @Autowired
    private EduVideoService eduVideoService;

    // 添加小节
    @PostMapping("addVideo")
    public Result addVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.save(eduVideo);
        return Result.ok();
    }

    // 删除小节时  删除对应的阿里云视频
    @DeleteMapping("deleteVideo/{videoId}")
    public Result deleteVideoById(@PathVariable String videoId) {
        boolean flag = eduVideoService.deleteVideoByVideoId(videoId);
        return flag ? Result.ok().message("删除成功") : Result.fail().message("删除失败");
    }

    // 根据Id查询小节
    @GetMapping("getVideo/{videoId}")
    public Result getVideoById(@PathVariable String videoId) {
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return Result.ok(eduVideo);
    }

    // 根据Id修改小节
    @PostMapping("updateVideo")
    public Result updateVideo(@RequestBody EduVideo eduVideo) {
        eduVideoService.updateById(eduVideo);
        return Result.ok();
    }
}

